package cn.elves.model.user.controller;

import cn.elves.model.entity.dto.response.ResponseDTO;
import cn.elves.model.user.service.VerificationCodeService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController("verificationCode")
public class VerificationCodeController {

    @Resource
    private VerificationCodeService verificationCodeService;

    @GetMapping("checkCode")
    public ResponseDTO<Boolean> checkCode(@RequestParam("phone") String phone, @RequestParam("code") String code) {
        Boolean isChecked = verificationCodeService.checkCode(phone, code);
        if (!isChecked) {
            return ResponseDTO.success();
        }
        return ResponseDTO.ofError("fail");
    }
}
